<?php
// <multiple crops summed yearly over multiple years. Multiple attributes.
$startYear = intval($startYear);
$endYear = intval($endYear);

//this simply creates the headers and creates an array containing the exact names of the selected attributes
$arrayOfSelectedAttributes = array();
if ($_GET['amount_harvested'] == 'on') {
	$arrayOfSelectedAttributes[] = 'amount_harvested';
}
if ($_GET['amount_donated'] == 'on') {
	$arrayOfSelectedAttributes[] = 'amount_donated';
}
if ($_GET['sales'] == 'on') {
	$arrayOfSelectedAttributes[] = 'sales';
}
if ($_GET['number_planted'] == 'on') {
	$arrayOfSelectedAttributes[] = 'number_planted';
}
if ($_GET['seeds_bought'] == 'on') {
	$arrayOfSelectedAttributes[] = 'seeds_bought';
}
if ($_GET['pest_issues'] == 'on') {
	$arrayOfSelectedAttributes[] = 'pest_issues';
}
if ($_GET['weed_issues'] == 'on') {
	$arrayOfSelectedAttributes[] = 'weed_issues';
}

$allCrops = $_GET['crops'];
$arrayOfCrops = explode(';', $allCrops);
foreach ($arrayOfCrops as $c) {
	$result = $result . "<th>" . $c . "</th>";
}


print "<form action=\"\">";
print "<select id=\"selectForm\" name=\"attributes\">";
foreach ($arrayOfSelectedAttributes as $a) {
	print "<option value=\"" . $a . "\">" . $a . "</option>";
}
print "</select>";
print "</form>";





$result = $result . "</tr></thead><tbody>";

$flag = 0;
$cropName = $_GET['crops'];

for($i = $startYear; $i <= $endYear; $i++){
	$result = $result . "<tr><td><img src=\"DataTables-1.7.3/details_open.png\" /></td><td>$i</td>";
	$endOfStartYear = $startYear . "-12-31";
	for ($j = 0; $j < count($arrayOfCrops); $j++) {
		if (!($flag)){ //for the first one, to have the right start date
			$cropRow = getMultiYearCropData($startDate, $endOfStartYear, getCropId($arrayOfCrops[$j]), $arrayOfSelectedAttributes[$j]);
			$flag = 1;
		}
		elseif ($i == $endYear) { //for the last one, to have the right end date
			$cropRow = getMultiYearCropData($i."01-01", $endDate, getCropId($cropName), $arrayOfSelectedAttributes[$j]);
		}
		else { //for all the in-between years, that aren't start or end years
			$cropRow = getMultiYearCropData($i."-01-01", $i."-12-31", getCropId($cropName), $arrayOfSelectedAttributes[$j]);
		
		}
		foreach ($cropRow as $year => $result1) { //print out the data into the cell
			$result = $result . "<td>" . $result1 . "</td>";
		}
		if (count($cropRow) == 0) { //if there is no data, print an empty cell
			$result = $result . "<td></td>";
		}
	}	
	$result = $result . "</tr>";
}
?>